package com.apes.framework.plugin.esb.processor.jpa;

import com.apes.framework.plugin.esb.api.Request;
import com.apes.framework.plugin.esb.processor.AbstractChainProcessor;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能：JPA查询权限
 *
 * @author xul
 * @create 2018-07-11 9:56
 */
@Data
public class NativeAuthProcessor<T extends Request, R> extends AbstractChainProcessor<T, R> {
    private String field;  //字段
    private String operator = "in"; //操作
    private String purpose;  //所属、操作、查询、......
    private String type;  //公司、部门、仓库、网点、物流站点......
    private String exp;

    @Override
    protected R doProcess(T source) {
        Map result = source.getMap();
        List<Map> auth;
        if (result.containsKey("nativeAuth")) {
            auth = (List<Map>) result.get("nativeAuth");
        } else {
            auth = new ArrayList<>();
            result.put("nativeAuth", auth);
        }
        Map m = new HashMap();
        m.put("field", field);
        m.put("operator", operator);
        m.put("purpose", purpose);
        m.put("type", type);
        m.put("exp", exp);
        auth.add(m);
        return (R) result;
    }


}
